package com.dhecp.project.flowable.cmd;

import org.flowable.common.engine.impl.interceptor.Command;
import org.flowable.common.engine.impl.interceptor.CommandContext;
import org.flowable.job.service.impl.util.CommandContextUtil;
import org.flowable.task.service.impl.persistence.entity.HistoricTaskInstanceEntity;

import java.util.Date;

/**
 * @ClassName UpdateHiTaskReasonCommand
 * @Description 更新任务原因命令
 * @Author alula
 * @Date 2019-12-09 9:56
 */
public class UpdateHiTaskReasonCommand implements Command<Object> {
    protected String taskId;
    protected String deleteReason;

    public UpdateHiTaskReasonCommand(String taskId, String deleteReason) {
        this.taskId = taskId;
        this.deleteReason = deleteReason;
    }
    @Override
    public Void execute(CommandContext commandContext) {
        HistoricTaskInstanceEntity historicTaskInstance = CommandContextUtil.getDbSqlSession().selectById(HistoricTaskInstanceEntity.class,taskId);
        if (historicTaskInstance != null) {
            historicTaskInstance.markEnded(deleteReason, new Date());
        }
        return null;
    }
}
